home *** CD-ROM | disk | FTP | other *** search
- #ifndef __WINDOWHANDLER__
- #define __WINDOWHANDLER__
-
- #include <Windows.h>
- #include <Events.h>
- #include "Exceptions.h"
-
- #define kMagicWindowHandlerID 'whid'
-
- #define eNoWindowHandler -31113
-
- //
- // Place an instance of this class in the RefCon of a toolbox window
- // to handle window events. Create a derived class to customize
- // the event handling (which, by default, does nothing).
- //
- class TWindowHandler
- {
- protected:
- long fMagicWindowHandlerID;
- WindowPtr fWindow;
-
- public:
- TWindowHandler() : fMagicWindowHandlerID(kMagicWindowHandlerID), fWindow(nil) {};
- virtual ~TWindowHandler();
- void IWindowHandler(WindowPtr window);
-
- Boolean IsValidHandler() { return fMagicWindowHandlerID == kMagicWindowHandlerID; }
- WindowPtr ToolboxWindow() { Require(fWindow != nil); return fWindow; }
- Rect* PortRect() { return &(((WindowPeek)ToolboxWindow())->port.portRect); }
-
- //
- // Toolbox event handling
- //
- virtual void Idle(EventRecord* event);
- virtual Boolean KeyDown(EventRecord* event, char keyPressed);
- virtual void Update(EventRecord* event);
- virtual void Activate(EventRecord* event);
- virtual void Deactivate(EventRecord* event);
- virtual void Resume(EventRecord* event);
- virtual void Suspend(EventRecord* event);
-
- //
- // Other event handling
- //
- virtual Boolean ContentClick(EventRecord* event);
- virtual void ResizeWindow(Point where);
- virtual void CloseAndDelete();
- virtual void CloseWindowByUser();
-
- //
- // Set the shape of the cursor:
- //
- virtual Boolean SetupCursorShape(Point localMousePoint, RgnHandle localMouseRgn);
-
- //
- // Menu handling
- //
- virtual void SetupMenus();
- virtual Boolean ProcessMenuSelection(short commandID);
-
- //
- // Modeless-dialog event handling (not applicable to windows that are not
- // modeless dialog boxes)
- //
- virtual void DialogManagerEvent(EventRecord* event, short itemHit);
- };
-
- //
- // Modeless dialog boxes will set the cursor shape to an I-beam
- // when it is over a TextEdit object
- //
- // (Handle cut-copy-paste too?)
- //
- class TModelessDialogHandler : public TWindowHandler
- {
- public:
- TModelessDialogHandler() {};
- virtual ~TModelessDialogHandler();
- void IModelessDialogHandler(DialogPtr dialog);
-
- DialogPtr DialogBoxPtr() { return (DialogPtr)fWindow; }
-
- virtual Boolean KeyDown(EventRecord* event, char keyPressed);
- virtual Boolean ContentClick(EventRecord* event);
-
- virtual void CloseAndDelete();
- virtual Boolean SetupCursorShape(Point localMousePoint, RgnHandle localMouseRgn);
- };
-
- //
- // Safe method for extracting a window handler from the refCon of a window
- //
- TWindowHandler* GetWindowHandler(WindowPtr window);
-
- inline TWindowHandler* FrontWindowHandler()
- {
- return GetWindowHandler(FrontWindow());
- }
-
- #endif
-